package com.bank.frame;

import com.bank.dao.UserDAO;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * 修改登录密码
 */
public class PasswordPanel extends JInternalFrame {
    public PasswordPanel() {
        super("修改密码", true, true, true, true);
        // 创建内容面板
        JPanel panel = new JPanel();
        // 设置内部窗口的内容面板
        this.setContentPane(panel);

        JPasswordField pwdField = new JPasswordField(10);
        panel.add(new JLabel("新密码"));
        panel.add(pwdField);

        JButton btn = new JButton("提交");
        btn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                String password = new String(pwdField.getPassword());
                UserDAO.updatePassword(MainFrame.user.getUsername(), password);
                MainFrame.frame.setContentPane(new LoginPanel());
            }
        });
        panel.add(btn);
        // 显示内部窗口
        this.setVisible(true);
    }
}
